home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Demo app / DemoFatRes.c next >
Encoding:
C/C++ Source or Header  |  1997-01-19  |  4.5 KB  |  214 lines  |  [TEXT/CWIE]

  1. #include "Find_icon.h"
  2.  
  3. /* Constants */
  4. enum
  5. {
  6.     eDLOG_ID = 128,
  7.     
  8.     // dialog items
  9.     eDoneButton = 1,
  10.     eStartStopButton,
  11.     eMaxSpeedCheckbox,
  12.     eBig8Icon,
  13.     eBig4Icon,
  14.     eBigBWIcon,
  15.     eSmall8Icon,
  16.     eSmall4Icon,
  17.     eSmallBWIcon,
  18.     eFileName
  19. };
  20.  
  21. /* Globals */
  22. FSSpec    gTheFile;
  23. Boolean    gAnimating = false;
  24. Boolean    gMaxSpeed = false;
  25. Find_icon_UPP    gFindIcon = NULL;
  26.     
  27. /* Prototypes */
  28. void Initialize(void);
  29. void main(void);
  30.  
  31. static void SetUserItemProc( DialogPtr dp, short item, UserItemUPP callback )
  32. {
  33.     short        iType;
  34.     Rect        iRect;
  35.     Handle        dummyH;
  36.     
  37.     GetDialogItem( dp, item, &iType, &dummyH, &iRect );
  38.     SetDialogItem( dp, item, iType, (Handle)callback, &iRect );
  39. }
  40.  
  41. static void InvalItem( DialogPtr dp, short item )
  42. {
  43.     short        iType;
  44.     Rect        iRect;
  45.     Handle        dummyH;
  46.     
  47.     GetDialogItem( dp, item, &iType, &dummyH, &iRect );
  48.     InvalRect( &iRect );
  49. }
  50.  
  51. static OSErr    NextFile( short index )
  52. {
  53.     CInfoPBRec    pb;
  54.     OSErr        err;
  55.     
  56.     pb.hFileInfo.ioNamePtr = gTheFile.name;
  57.     pb.hFileInfo.ioVRefNum = gTheFile.vRefNum;
  58.     pb.hFileInfo.ioDirID = gTheFile.parID;
  59.     pb.hFileInfo.ioFDirIndex = index;
  60.     err = PBGetCatInfoSync( &pb );
  61.     return err;
  62. }
  63.  
  64. static pascal Boolean ModalFilterProc(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
  65. {
  66.     ModalFilterUPP    standardFilter;
  67.     static unsigned long    lastIncTime = 0;
  68.     static long    fileIndex = 0;
  69.     OSErr    err;
  70.     
  71.     GetStdFilterProc( &standardFilter );
  72.     
  73.     if ( gAnimating && (theEvent->what == nullEvent) )
  74.     {
  75.         if ( gMaxSpeed || (TickCount() - lastIncTime > 60) )
  76.         {
  77.             fileIndex += 1;
  78.             err = NextFile( fileIndex );
  79.             if (err == fnfErr)
  80.             {
  81.                 fileIndex = 1;
  82.                 NextFile( fileIndex );
  83.             }
  84.             ParamText( gTheFile.name, NULL, NULL, NULL );
  85.             InvalItem( theDialog, eFileName );
  86.             InvalItem( theDialog, eBig8Icon );
  87.             InvalItem( theDialog, eBig4Icon );
  88.             InvalItem( theDialog, eBigBWIcon );
  89.             InvalItem( theDialog, eSmall8Icon );
  90.             InvalItem( theDialog, eSmall4Icon );
  91.             InvalItem( theDialog, eSmallBWIcon );
  92.             lastIncTime = TickCount();
  93.         }
  94.     }
  95.     
  96.     return CallModalFilterProc( standardFilter, theDialog, theEvent, itemHit );
  97. }
  98.  
  99.  
  100. static pascal void IconItemProc(WindowPtr theWindow, short itemNo)
  101. {
  102.     short        iType;
  103.     Rect        iRect;
  104.     Handle        dummyH;
  105.     Handle        suite;
  106.     OSErr        err;
  107.     MetaSelectorValue    selector;
  108.     
  109.     GetDialogItem( theWindow, itemNo, &iType, &dummyH, &iRect );
  110.     switch( itemNo )
  111.     {
  112.         case eBig8Icon:
  113.         case eSmall8Icon:
  114.             selector = kSelectorAllAvailableData;
  115.             break;
  116.             
  117.         case eBig4Icon:
  118.         case eSmall4Icon:
  119.             selector = kSelectorAll4BitData | kSelectorAll1BitData;
  120.             break;
  121.             
  122.         case eBigBWIcon:
  123.         case eSmallBWIcon:
  124.             selector = kSelectorAll1BitData;
  125.             break;
  126.     }
  127.     
  128.     EraseRect( &iRect );
  129.     
  130.     err = CallFindIcon( gFindIcon, &gTheFile, selector, &suite );
  131.     if (err == noErr)
  132.     {
  133.         PlotIconSuite( &iRect, kAlignNone, kTransformNone, suite );
  134.         DisposeIconSuite( suite, true );
  135.     }
  136. }
  137.  
  138. //MW specified argument and return type.
  139. void main(void)
  140. {
  141.     DialogPtr    dp;
  142.     short        itemHit;
  143.     ControlHandle    maxSpeedCheckbox;
  144.     short        iType;
  145.     Rect        iRect;
  146.     UserItemUPP    iconItemUPP;
  147.     ProcessSerialNumber    myPSN = { kNoProcess, kCurrentProcess };
  148.     ProcessInfoRec        pInfo;
  149.     Handle        findIconProc;
  150.     ModalFilterUPP    myFilter;
  151.     
  152.     Initialize();
  153.     
  154.     findIconProc = GetResource( 'PROC', 128 );
  155.     if (findIconProc == NULL)
  156.     {
  157.         return;
  158.     }
  159.     HLock( findIconProc );
  160.     gFindIcon = (Find_icon_UPP) *findIconProc;
  161.     
  162.     dp = GetNewDialog( eDLOG_ID, NULL, (WindowPtr) -1L );
  163.     SetPort( dp );
  164.     SetDialogDefaultItem( dp, eDoneButton );
  165.     ShowWindow( dp );
  166.     GetDialogItem( dp, eMaxSpeedCheckbox, &iType, (Handle*) &maxSpeedCheckbox, &iRect );
  167.     
  168.     iconItemUPP = NewUserItemProc( IconItemProc );
  169.     SetUserItemProc( dp, eBig8Icon, iconItemUPP );
  170.     SetUserItemProc( dp, eBig4Icon, iconItemUPP );
  171.     SetUserItemProc( dp, eBigBWIcon, iconItemUPP );
  172.     SetUserItemProc( dp, eSmall8Icon, iconItemUPP );
  173.     SetUserItemProc( dp, eSmall4Icon, iconItemUPP );
  174.     SetUserItemProc( dp, eSmallBWIcon, iconItemUPP );
  175.     
  176.     myFilter = NewModalFilterProc( ModalFilterProc );
  177.     
  178.     pInfo.processInfoLength = sizeof(pInfo);
  179.     pInfo.processName = NULL;
  180.     pInfo.processAppSpec = &gTheFile;
  181.     GetProcessInformation( &myPSN, &pInfo );
  182.     
  183.     ParamText( gTheFile.name, NULL, NULL, NULL );
  184.     
  185.     do {
  186.         ModalDialog( myFilter, &itemHit );
  187.         if (itemHit == eMaxSpeedCheckbox)
  188.         {
  189.             gMaxSpeed = !gMaxSpeed;
  190.             SetControlValue( maxSpeedCheckbox, gMaxSpeed );
  191.         }
  192.         else if (itemHit == eStartStopButton)
  193.         {
  194.             gAnimating = !gAnimating;
  195.         }
  196.     } while (itemHit != eDoneButton);
  197.     
  198.     DisposeDialog( dp );
  199. }
  200.  
  201. void Initialize(void)
  202. {
  203.     /* Initialize all the needed managers. */
  204.     InitGraf(&qd.thePort);
  205.     InitFonts();
  206.     InitWindows();
  207.     InitMenus();
  208.     TEInit();
  209.     InitDialogs(nil);
  210.     InitCursor();
  211. }
  212.  
  213.  
  214.